package com.example.demo2;

import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;

import java.io.File;
import java.io.IOException;

public class xxywMainActivity extends AppCompatActivity {

    private Button Bu3;
    private Button Bu1,Bu2;
    private boolean isPause=false;
    private MediaPlayer mediaPlayer;
    //File file = new File("/sdcard/kiki.mp3");
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xxyw_main);


        final MediaPlayer mediaPlayer = MediaPlayer.create(this,R.raw.kiki);

        Bu1 = (Button)findViewById(R.id.Bu1);
        Bu2 = (Button)findViewById(R.id.Bu2);
        Bu3 = (Button)findViewById(R.id.Bu3);
        mediaPlayer.start();//开始播放音频

        Bu1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mediaPlayer.isPlaying()&&!isPause){
                    mediaPlayer.pause();
                    isPause=true;
//                    ((ImageButton)v).setImageDrawable(getResources().getDrawable(R.drawable.bof,null));
                }
                else{
                mediaPlayer.start();
//                Bu1.setImageDrawable(getResources().getDrawable(R.drawable.zta,null));
                    isPause=false;
//                    ((ImageButton)v).setImageDrawable(getResources().getDrawable(R.drawable.zta,null));
                }
                //mediaPlayer.start();//开始播放音频
            }
        });
        Bu2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mediaPlayer.pause();//暂停操作
//                mediaPlayer.stop();
//                Bu1.setImageDrawable(getResources().getDrawable(R.drawable.bof,null));
            }
        });
//        //设置完成事件监听器
//        mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
//            @Override
//            public void onCompletion(MediaPlayer mp) {
//                //play();//用于实现重新播放的功能
//            }
//        });
        Bu3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mediaPlayer.stop();//停止操作
            }
        });

    }
//    private void play(){
//        mediaPlayer.reset();
//        try {
//            mediaPlayer.setDataSource(file.getAbsolutePath());
//            mediaPlayer.prepare();
//            mediaPlayer.start();
//        }catch (IOException e){
//                e.printStackTrace();
//        }
//    }
//
//    @Override
//    protected void onDestroy() {
//        if()
//        super.onDestroy();
//    }
}
